package com.wlr.blog.job;

import lombok.extern.slf4j.Slf4j;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.BeanUtils;

/**
 * @author lrwang
 * @version 1.0
 * @date 2022/11/22 10:08
 */
@Slf4j
public abstract class AbstractQuartzJob implements Job {
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        SysJob sysJob = new SysJob();
        BeanUtils.copyProperties(jobExecutionContext.getMergedJobDataMap().get("key"), sysJob);
        before(jobExecutionContext, sysJob);
        executeInternal(jobExecutionContext, sysJob);
        after(jobExecutionContext, sysJob);
    }

    /**
     * 执行方法
     *
     * @param jobExecutionContext
     * @param sysJob
     */
    protected abstract void executeInternal(JobExecutionContext jobExecutionContext, SysJob sysJob);

    protected void before(JobExecutionContext context, SysJob job) {
        log.info("quartz before execute completed");
    }

    protected void after(JobExecutionContext context, SysJob job) {
        log.info("quartz after execute completed");
    }
}
